Skip to content

Conversation

@srittau
Copy link
Collaborator

@srittau srittau commented Mar 20, 2025

No description provided.

@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Member

I haven't fully thought this through but #13519 partially made me think that making memoryview generic with a default was a mistake. memoryview now means memoryview[int], so if you have a memoryview[bytes] you can't pass it to a function that wants a plain memoryview. But usually that's wrong; lots of memoryview functionality doesn't depend on the type parameter and lots of functions will work with any kind of memoryview.

@srittau
Copy link
Collaborator Author

srittau commented Mar 20, 2025

I was thinking about that, but I think changing the default to Any might be a better solution. That keeps the flexibility of restricting memoryviews while by default any memoryview is accepted.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Diff from mypy_primer, showing the effect of this PR on open source code:

trio (https://github.com/python-trio/trio)
+ src/trio/_abc.py:331: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/_highlevel_socket.py:109: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/_highlevel_generic.py:94: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/_file_io.py:164: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/_file_io.py:330: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/_ssl.py:737: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/_subprocess.py:466: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/_subprocess.py:1155: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/_subprocess.py:1164: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/testing/_memory_streams.py:44: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/testing/_memory_streams.py:122: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/testing/_memory_streams.py:270: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/testing/_memory_streams.py:499: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/testing/_memory_streams.py:568: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/testing/_check_streams.py:101: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/testing/_check_streams.py:469: error: Explicit "Any" is not allowed  [explicit-any]
+ src/trio/_tests/test_ssl.py:802: error: Explicit "Any" is not allowed  [explicit-any]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_implementations.py:1155: error: No overload variant of "builds" of "BuildsFn" matches argument types "type[DataclassInstance]", "dict[str, int | float | Path | DataClass_ | type[DataClass_] | ListConfig | DictConfig | Enum | Sequence[HydraSupportedType] | Mapping[Any, HydraSupportedType] | None]", "bool | None", "Literal['none', 'partial', 'all', 'object'] | None", "DataclassOptions"  [call-overload]
+ src/hydra_zen/structured_configs/_implementations.py:1155: error: No overload variant of "builds" of "BuildsFn" matches argument types "type[DataclassInstance]", "dict[str, int | float | memoryview[Any] | Path | DataClass_ | <6 more items> | None]", "bool | None", "Literal['none', 'partial', 'all', 'object'] | None", "DataclassOptions"  [call-overload]
- src/hydra_zen/structured_configs/_implementations.py:2712: error: Incompatible types in assignment (expression has type "tuple[int | float | Path | DataClass_ | type[DataClass_] | ListConfig | DictConfig | Enum | Sequence[HydraSupportedType] | Mapping[Any, HydraSupportedType] | None, ...]", variable has type "list[Importable | Callable[P, R] | type[Builds[Importable]] | type[BuildsWithSig[Importable, Any]] | type[BuildsWithSig[type[R], P]] | Any]")  [assignment]
+ src/hydra_zen/structured_configs/_implementations.py:2712: error: Incompatible types in assignment (expression has type "tuple[int | float | memoryview[Any] | Path | DataClass_ | <6 more items> | None, ...]", variable has type "list[Importable | Callable[P, R] | type[Builds[Importable]] | type[BuildsWithSig[Importable, Any]] | type[BuildsWithSig[type[R], P]] | Any]")  [assignment]

core (https://github.com/home-assistant/core)
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:141: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:141: note: "__init_subclass__" of "object" defined here

aioredis (https://github.com/aio-libs/aioredis)
- aioredis/connection.py:933: error: Unsupported right operand type for in ("bytes | memoryview[int] | int")  [operator]
+ aioredis/connection.py:933: error: Unsupported right operand type for in ("bytes | memoryview[Any] | int")  [operator]
- aioredis/connection.py:934: error: Item "memoryview[int]" of "bytes | memoryview[int] | int" has no attribute "split"  [union-attr]
+ aioredis/connection.py:934: error: Item "memoryview[Any]" of "bytes | memoryview[Any] | int" has no attribute "split"  [union-attr]
- aioredis/connection.py:934: error: Item "int" of "bytes | memoryview[int] | int" has no attribute "split"  [union-attr]
+ aioredis/connection.py:934: error: Item "int" of "bytes | memoryview[Any] | int" has no attribute "split"  [union-attr]
- aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview[int], Any | None]", variable has type "dict[bytes | str | memoryview[int], Callable[[dict[str, str]], Awaitable[None]]]")  [assignment]
+ aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview[Any], Any | None]", variable has type "dict[bytes | str | memoryview[Any], Callable[[dict[str, str]], Awaitable[None]]]")  [assignment]
- aioredis/client.py:4158: error: Argument 1 to "update" of "MutableMapping" has incompatible type "dict[bytes | str | memoryview[int], Any | None]"; expected "SupportsKeysAndGetItem[bytes | str | memoryview[int], Callable[[dict[str, str]], Awaitable[None]]]"  [arg-type]
+ aioredis/client.py:4158: error: Argument 1 to "update" of "MutableMapping" has incompatible type "dict[bytes | str | memoryview[Any], Any | None]"; expected "SupportsKeysAndGetItem[bytes | str | memoryview[Any], Callable[[dict[str, str]], Awaitable[None]]]"  [arg-type]
- aioredis/client.py:4172: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview[int], Callable[[dict[str, str]], Awaitable[None]]]", variable has type "dict[Any, Any | None]")  [assignment]
+ aioredis/client.py:4172: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview[Any], Callable[[dict[str, str]], Awaitable[None]]]", variable has type "dict[Any, Any | None]")  [assignment]

zulip (https://github.com/zulip/zulip)
- ...typeshed_to_test/stdlib/builtins.pyi:118: note: "SubTest" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:119: note: "SubTest" defined here

ibis (https://github.com/ibis-project/ibis)
- ...typeshed_to_test/stdlib/builtins.pyi:118: note: "Any" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:119: note: "Any" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:118: note: "__init__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:119: note: "__init__" of "object" defined here

prefect (https://github.com/PrefectHQ/prefect)
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:141: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:141: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:141: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:141: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:141: note: "__init_subclass__" of "object" defined here

arviz (https://github.com/arviz-devs/arviz)
- arviz/data/inference_data.py:500: note:     def to_netcdf(self, path: None = ..., mode: Literal['w', 'a'] = ..., format: Literal['NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT', 'NETCDF3_CLASSIC'] | None = ..., group: str | None = ..., engine: Literal['netcdf4', 'scipy', 'h5netcdf'] | None = ..., encoding: Mapping[Any, Mapping[str, Any]] | None = ..., unlimited_dims: Iterable[Hashable] | None = ..., compute: bool = ..., invalid_netcdf: bool = ..., auto_complex: bool | None = ...) -> memoryview[int]
+ arviz/data/inference_data.py:500: note:     def to_netcdf(self, path: None = ..., mode: Literal['w', 'a'] = ..., format: Literal['NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT', 'NETCDF3_CLASSIC'] | None = ..., group: str | None = ..., engine: Literal['netcdf4', 'scipy', 'h5netcdf'] | None = ..., encoding: Mapping[Any, Mapping[str, Any]] | None = ..., unlimited_dims: Iterable[Hashable] | None = ..., compute: bool = ..., invalid_netcdf: bool = ..., auto_complex: bool | None = ...) -> memoryview[Any]

strawberry (https://github.com/strawberry-graphql/strawberry)
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:141: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:141: note: "__init_subclass__" of "object" defined here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants